home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************************\
-
- File: sfx meat.c
-
- Purpose: This module handles the fade modules folder: setting up
- the two lists based on the initial information, setting
- information of fades.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program in a file named "GNU General Public License".
- If not, write to the Free Software Foundation, 675 Mass Ave,
- Cambridge, MA 02139, USA.
-
- \**********************************************************************/
-
- #include "Folders.h"
- #include "sfx meat.h"
- #include "program globals.h"
-
- static long gModuleDirID;
- static short gModuleVRefNum;
-
- short HowManyModulesInstalledQQ(short *theAnswer, short *theOtherAnswer)
- /* return value is error code; number of installed modules passed back in *theAnswer */
- {
- CInfoPBRec pb;
- OSErr isHuman;
- Str255 theName;
- long systemDirID;
- short i;
- short numModulesInstalled;
- short numModules;
-
- isHuman=FindFolder(kOnSystemDisk, kSystemFolderType, kDontCreateFolder, &gModuleVRefNum,
- &systemDirID); /* find system folder */
- if (isHuman!=noErr)
- return kCantFindSystemFolder;
-
- pb.dirInfo.ioCompletion=0L;
- pb.dirInfo.ioNamePtr=MODULE_FOLDER;
- pb.dirInfo.ioVRefNum=gModuleVRefNum;
- pb.dirInfo.ioFDirIndex=0; /* very important */
- pb.dirInfo.ioDrDirID=systemDirID;
- isHuman=PBGetCatInfo(&pb, FALSE); /* get info on "MSG Fades ƒ" folder */
- if (isHuman!=noErr)
- return kCantFindModuleFolder;
-
- gModuleDirID=pb.dirInfo.ioDrDirID;
- numModules=pb.dirInfo.ioDrNmFls;
- numModulesInstalled=0;
-
- for (i=1; i<=numModules; i++)
- {
- pb.hFileInfo.ioCompletion=0L;
- pb.hFileInfo.ioNamePtr=theName;
- pb.hFileInfo.ioVRefNum=gModuleVRefNum;
- pb.hFileInfo.ioFDirIndex=i;
- pb.hFileInfo.ioDirID=gModuleDirID;
- isHuman=PBGetCatInfo(&pb, FALSE);
- if ((isHuman==noErr) && (!(pb.hFileInfo.ioFlAttrib&0x10)) &&
- (pb.hFileInfo.ioFlFndrInfo.fdCreator==CREATOR))
- {
- /* got a fade module, now find out if it's used or unused */
-
- if (pb.hFileInfo.ioFlFndrInfo.fdType==USED_TYPE)
- {
- numModulesInstalled++;
- }
- }
- }
-
- *theAnswer=numModulesInstalled;
- *theOtherAnswer=numModules;
-
- return 0;
- }
-
- short GetAModule(short *index, Str255 theName, short *vRefNum, long *dirID)
- /* return value is error code; module info is passed back in params */
- {
- CInfoPBRec pb;
- OSErr isHuman;
- short i;
- short numModules;
- short numModulesInstalled;
- short resultCode;
- short ourModuleIndex;
- unsigned long dummy;
-
- if ((resultCode=HowManyModulesInstalledQQ(&numModulesInstalled, &numModules))!=0)
- return resultCode;
-
- if (numModules==0)
- return kNoModulesInFolder;
-
- if (numModulesInstalled==0)
- return kNoModulesInstalled;
-
- if (gChooseRandom)
- {
- GetDateTime(&dummy);
- ourModuleIndex=1+((dummy&0x7fffffff)%numModulesInstalled);
- }
- else
- {
- ourModuleIndex=*index;
- while (ourModuleIndex>=numModulesInstalled)
- ourModuleIndex-=numModulesInstalled;
- ourModuleIndex++;
- }
-
- for (i=1; ((i<=numModules) && (ourModuleIndex>0)); i++)
- {
- pb.hFileInfo.ioCompletion=0L;
- pb.hFileInfo.ioNamePtr=theName;
- pb.hFileInfo.ioVRefNum=gModuleVRefNum;
- pb.hFileInfo.ioFDirIndex=i;
- pb.hFileInfo.ioDirID=gModuleDirID;
- isHuman=PBGetCatInfo(&pb, FALSE);
- if ((isHuman==noErr) && (!(pb.hFileInfo.ioFlAttrib&0x10)) &&
- (pb.hFileInfo.ioFlFndrInfo.fdCreator==CREATOR))
- {
- /* got a fade module, now find out if it's used or unused */
-
- if (pb.hFileInfo.ioFlFndrInfo.fdType==USED_TYPE)
- {
- ourModuleIndex--;
- }
- }
- }
-
- *index=i-1;
- *vRefNum=gModuleVRefNum;
- *dirID=gModuleDirID;
- /* name is already in parameter from PBGetCatInfo call */
-
- return 0;
- }
-